<template>
    <el-form ref="form" label-width="80px" class="mt">
                <el-form-item label="开卡客户">
                    <div style="height:62px">
                        <div style="width:400px; float: left" v-show="order.ginfo.id">
                            <el-card :body-style="{ padding: '0px' }">
                                <el-row>
                                    <div style="float: left;height: 60px;margin-right: 10px">
                                        <img :src="order.ginfo.headurl" style="border-radius: 50%; width: 50px; height:50px;padding: 5px">
                                    </div>
                                    <div style="float: left;height: 60px;">
                                        <p style="margin: 0px; height: 30px">
                                            <span @click="openGuestPage(order.ginfo.id)" style="cursor:pointer;color:#f50">{{order.ginfo.name}}</span>
                                            <span style="margin-left: 10px;font-size: 13px;color: #999;">{{order.ginfo.phone}}</span>
                                        </p>
                                        <p style="margin: 0px; height: 30px">
                                            vip：<span style="font-size: 13px;color: #999;">{{order.ginfo.vipcard}}</span> 产品折扣：
                                            <span style="font-size: 13px;color: #999;">{{order.ginfo.goodsdiscount}}</span> 项目折扣：
                                            <span style="font-size: 13px;color: #999;">{{order.ginfo.subjectdiscount}}</span>
                                        </p>
                                    </div>
                                </el-row>
                            </el-card>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item label="开卡列表">
                    <el-row :gutter="10">
                        <el-table :data="order.orderlist" height="350" show-summary :summary-method="summary">
                            <el-table-column prop="name" label="名称"></el-table-column>
                            <el-table-column prop="typeid" label="类型">
                                <template scope="scope">
                                    <el-tag type="success" v-if="scope.row.rowtype===1">
                                        产品
                                    </el-tag>
                                    <el-tag type="primary" v-if="scope.row.rowtype===2">
                                        项目
                                    </el-tag>
                                    <el-tag type="danger" v-if="scope.row.rowtype===3">
                                        卡项
                                    </el-tag>
                                </template>
                            </el-table-column>
                            <el-table-column prop="price" label="标准价格">
                                <template scope="scope">{{scope.row.price+'元'}}</template>
                            </el-table-column>
                            <el-table-column prop="num" label="数量" width="50">
                            </el-table-column>
                            <el-table-column prop="discount" label="折扣（0-1）" width="100">
                            </el-table-column>
                            <el-table-column prop="amount" label="小计" width="100">
                            </el-table-column>
                            <el-table-column prop="usemoney" label="现金">
                            </el-table-column>
                            <el-table-column prop="usebalance" label="余额">
                            </el-table-column>
                            <el-table-column prop="usegiftbalance" label="赠送余额">
                            </el-table-column>
                            <el-table-column prop="validity" label="有效期">
                                <template scope="scope">{{scope.row.validity?scope.row.validity+'天':'用完为止'}}</template>
                            </el-table-column>
                            <el-table-column prop="" label="赠">
                                <template scope="scope">
                                    <el-tag type="success" v-if="scope.row.isgift===1">是</el-tag>
                                    <el-tag type="danger" v-if="scope.row.isgift===0">否</el-tag>
                                </template>
                            </el-table-column>
                            <el-table-column prop="cost" label="成本">
                                <template scope="scope">{{scope.row.cost}}%</template>
                            </el-table-column>
                        </el-table>
                    </el-row>
                </el-form-item>
                <el-form-item label="开卡描述">
                    <el-input type="textarea" v-model="order.remarks" placeholder="请输入开卡描述，方便了解该订单。（可忽略）" disabled></el-input>
                </el-form-item>
    </el-form>
</template>
<script>
import Guest from '#/src/shop/guest.js'
export default {
    name: 'addOpenCard',
    props: ['order'],
    data() {
        return {
        }
    },
    methods: {
        summary: function(param) {
            const { columns, data } = param
            const sums = []
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '合计'
                    return
                }
                if (index == 5 || index == 6 || index == 7 || index == 8) {
                    const values = data.map(item => Number(item[column.property]))
                    if (!values.every(value => isNaN(value))) {
                        sums[index] = values.reduce((prev, curr) => {
                            const value = Number(curr)
                            if (!isNaN(value)) {
                                return prev + curr
                            } else {
                                return prev
                            }
                        }, 0)
                        sums[index] = sums[index].toFixed(2)
                    } else {
                        sums[index] = 'N/A'
                    }
                }
            })
            return sums
        },
        openGuestPage(id) {
            Guest.openGuestPage(id)
        }
    },
    mounted: async function() {
    }
}
</script>
<style>
</style>